package Controller;

import Beans.AreaBean;
import Beans.SalonBean;
import DAO.HibernateAreaDAO;
import DAO.HibernateSalonDAO;
import DTO.SalonDTO;
import Model.Salon;

public class AdministradorSalon {
	
	private static AdministradorSalon instancia;
	private AdministradorSalon(){
		
	}
	
	public static AdministradorSalon getInstancia(){
		if(instancia==null)
			instancia=new AdministradorSalon();
		return instancia;
	}
	
	public void grabarSalon (SalonDTO s){
		HibernateSalonDAO.getInstancia().grabarSalon(s);
		
	}

	public SalonBean fromModelTOBean(Salon salon) {
		SalonBean salonBean=null;
		if(salon!=null){
		salonBean=new SalonBean();
		salonBean.setIdSalon(salon.getId());
		salonBean.setNombre(salon.getNombre());
		salonBean.setReservas(AdministradorReserva.getInstancia().fromModelTOBean(salon.getReservas()));
		salonBean.setSectores(AdministradorSector.getInstancia().fromModelTOBean(salon.getSectores()));
		salonBean.setComandas(AdministradorComanda.getInstancia().fromModelTOBean(salon.getComandas()));
		}
		return salonBean;
	}

	public Salon fromDTOTOModel(SalonDTO salonDTO) {
		Salon salon=null;
		if(salonDTO!=null){
		salon=new Salon();
		salon.setId(salonDTO.getId());
		salon.setNombre(salonDTO.getNombre());
		salon.setReservas(AdministradorReserva.getInstancia().fromDTOTOModel(salonDTO.getReservas()));
		salon.setSectores(AdministradorSector.getInstancia().fromDTOTOModel(salonDTO.getSectores()));
		salon.setComandas(AdministradorComanda.getInstancia().fromDTOTOModel(salonDTO.getComandas()));
		}
		return salon;
	}
	
	
	public SalonDTO fromModelTODTO(Salon salon) {
		SalonDTO salonDTO=null;
		if(salon!=null){
			salonDTO=new SalonDTO();
			salonDTO.setId(salon.getId());
			salonDTO.setNombre(salon.getNombre());
			salonDTO.setReservas(AdministradorReserva.getInstancia().fromModelTODTO(salon.getReservas()));
			salonDTO.setSectores(AdministradorSector.getInstancia().fromModelTODTO(salon.getSectores()));
			salonDTO.setComandas(AdministradorComanda.getInstancia().fromModelTODTO(salon.getComandas()));
		}
		return salonDTO;
	}

	public Salon fromBeanTOModel(SalonBean salonBean) {
		Salon salon=null;
		if(salonBean!=null){
		salon=new Salon();
		salon.setId(salonBean.getIdSalon());
		salon.setNombre(salonBean.getNombre());
		salon.setReservas(AdministradorReserva.getInstancia().fromBeanTOModel(salonBean.getReservas()));
		salon.setSectores(AdministradorSector.getInstancia().fromBeanTOModel(salonBean.getSectores()));
		salon.setComandas(AdministradorComanda.getInstancia().fromBeanTOModel(salonBean.getComandas()));
		}
		return salon;
	}

	public Salon buscarSalon(Salon a) {
		SalonBean ab=fromModelTOBean(a);
		ab=HibernateSalonDAO.getInstancia().buscarSalon(ab);
		return fromBeanTOModel(ab);
	}

	
	

}
